package com.asset.salesforce.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.salesforce.model.Department;

@Repository
public class DepartmentDaoImpl {
	
	@Autowired 
	SessionFactory sessionFactory;
	public void addDepartment(Department department) {
		try{
		sessionFactory.getCurrentSession().save(department);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Department> getAllDepartment() {
		
		return sessionFactory.getCurrentSession().createQuery("from Department").list();
		
		
	}

	public void deletedepartment(Integer id) {
		Department department = (Department) sessionFactory.getCurrentSession().load(
				Department.class, id);
		if (null != department) {
			sessionFactory.getCurrentSession().delete(department);
		}
		
	}

}
